package com.xinlianshiye.im.bean

import java.time.Instant
import javax.persistence.*

/**
 * 用户聊天记录表
 */
@Entity
@Table(name = "im_record")
class Record: Domain() {

    @Column(columnDefinition = "text comment '聊天内容'")
    var content // 聊天内容
            : String? = null
    var type // 消息类型 0文字 1图片 2超连接 3自定义数据
            : Int? = null

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "from_user_id", foreignKey = ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT), updatable = false, insertable = false)
    var owner // 消息拥有者 》》》关联用户
            : User? = null

    @Column(name = "from_user_id")
    var ownerId: Int? = null

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "to_user_id", foreignKey = ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT), updatable = false, insertable = false)
    var other // 消息拥有的另一个人 》》》关联用户
            : User? = null

    @Column(name = "to_user_id")
    var otherId: Int? = null

    @Column(name = "state", columnDefinition = "tinyint(2) default 0 comment '是否已读 1: 已读, 0: 未读'")
    var haveRead: Boolean? = null

    @Column(name = "issend", columnDefinition = "tinyint(2) comment '是否为发送者 1: 代表发送者, 0: 代表接受者'")
    var isSender: Boolean? = null
}